package com.hspedu.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author: xujiabing
 * @date: 2024-12-01 17:27
 * @description: rabbitmq 配置类,可以创建队列，交换机(topic主题模式)
 */
@Configuration
public class RabbitMQTopicConfig {
    public static final String QUEUE01 = "queue_topic01";
    public static final String QUEUE02 = "queue_topic02";
    public static final String EXCHANGE = "topicExchange";
    public static final String ROUTING_KEY01 = "#.queue.#";
    public static final String ROUTING_KEY02 = "*.queue.#";

    @Bean
    public Queue queue_topic01() {
        return new Queue(QUEUE01);
    }

    @Bean
    public Queue queue_topic02() {
        return new Queue(QUEUE02);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(EXCHANGE);
    }

    @Bean
    public Binding binding_topic01() {
        return BindingBuilder.bind(queue_topic01()).to(topicExchange()).with(ROUTING_KEY01);
    }

    @Bean
    public Binding binding_topic02() {
        return BindingBuilder.bind(queue_topic02()).to(topicExchange()).with(ROUTING_KEY02);
    }
}
